/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.domain.analysis.results.averages;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author jmj
 */
public class Averages implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 5069636429689276102L;
    private List<AverageByDecadeFemale> femaleAverages;
    private List<AverageByDecadeMale> maleAverages;

    /**
     * @param femaleAverages
     * @param maleAverages
     */
    public Averages(List<AverageByDecadeFemale> femaleAverages, List<AverageByDecadeMale> maleAverages) {
        this.femaleAverages = femaleAverages;
        this.maleAverages = maleAverages;
    }

    /**
     * @return the femaleAverages
     */
    public List<AverageByDecadeFemale> getFemaleAverages() {
        return this.femaleAverages;
    }

    /**
     * @param femaleAverages the femaleAverages to set
     */
    public void setFemaleAverages(List<AverageByDecadeFemale> femaleAverages) {
        this.femaleAverages = femaleAverages;
    }

    /**
     * @return the maleAverages
     */
    public List<AverageByDecadeMale> getMaleAverages() {
        return this.maleAverages;
    }

    /**
     * @param maleAverages the maleAverages to set
     */
    public void setMaleAverages(List<AverageByDecadeMale> maleAverages) {
        this.maleAverages = maleAverages;
    }

    /**
     *
     * Return the female averages by decade
     *
     * @param decade Decade of averages
     * @return Averages od decade
     */
    public AverageByDecadeFemale getFemaleAverageByDecade(int decade) {
        AverageByDecadeFemale avg = null;
        boolean found = false;
        if (this.femaleAverages != null) {
            Iterator<AverageByDecadeFemale> it = this.femaleAverages.iterator();
            while ((it.hasNext()) && (!found)) {
                avg = it.next();
                found = (avg.getDecade() == decade);
            }
        }
        return (found ? avg : new AverageByDecadeFemale(decade));
    }

    /**
     *
     * Return the male averages by decade
     *
     * @param decade Decade of averages
     * @return Averages od decade
     */
    public AverageByDecadeMale getMaleAverageByDecade(int decade) {
        AverageByDecadeMale avg = null;
        boolean found = false;
        if (this.maleAverages != null) {
            Iterator<AverageByDecadeMale> it = this.maleAverages.iterator();
            while ((it.hasNext()) && (!found)) {
                avg = it.next();
                found = (avg.getDecade() == decade);
            }
        }
        return (found ? avg : new AverageByDecadeMale(decade));
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((this.femaleAverages == null) ? 0 : this.femaleAverages.hashCode());
        result = prime * result
                + ((this.maleAverages == null) ? 0 : this.maleAverages.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Averages other = (Averages) obj;
        if (this.femaleAverages == null) {
            if (other.femaleAverages != null) {
                return false;
            }
        } else if (!this.femaleAverages.equals(other.femaleAverages)) {
            return false;
        }
        if (this.maleAverages == null) {
            if (other.maleAverages != null) {
                return false;
            }
        } else if (!this.maleAverages.equals(other.maleAverages)) {
            return false;
        }
        return true;
    }
}
